#include "add_dish.h"
#include "ui_add_dish.h"
#include "business.h"
#include <QDebug>
#include<business.cpp>
#include<iostream>
#include<fstream>
#include<QMessageBox>
using namespace std;
add_dish::add_dish(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::add_dish)
{
    ui->setupUi(this);

}

add_dish::~add_dish()
{
    delete ui;
}
//设置菜品信息
void add_dish::set_inform(QStringList name,int id){
    qDebug()<<QString("获取菜品信息")<<endl;
    this->id=id;
    this->dish_name=name;
//    sale->id=1;
//    sale->window_id=10;
//    sale->name=QString("盖饭").toStdString();
//    sale->price=12;
//    sale->diningType=QString("称重").toStdString();
//    sale->unit=QString("斤").toStdString();
//    sale->desciption=QString("iubiubiu").toStdString();
//        qDebug()<<sale;
//    foods.push_back(sale);
//    sale->id=2;sale->window_id=10;sale->name=QString("蜘蛛").toStdString();sale->price=12;sale->diningType="组合";sale->unit="份";sale->desciption="iubiubiu";
//    foods.push_back(sale);
//    sale->id=3;sale->window_id=15;sale->name=QString("鸡公煲").toStdString();sale->price=15;sale->diningType="单价";sale->unit="份";sale->desciption="iubiubiu";
//    foods.push_back(sale);
//    qDebug()<< typeid(foods[0]->name).name();
//    qDebug()<<foods;
    //将菜品显示在面上
        int iRow = dish_name.size()-1;
        qDebug()<<QString("有")<<iRow<<QString("行");
        ui->tableWidget->setRowCount(iRow);
        ui->tableWidget->setColumnCount(2);
        for(int row=0;row<=iRow;row++)
        {
        qDebug()<<QString("插入行：")<<row;
        QTableWidgetItem *check = new QTableWidgetItem();
        check->setCheckState(Qt::Unchecked);

        ui->tableWidget->setItem(row,0,check);
//        string foodname1=foods[row]->name;
        ui->tableWidget->setItem(row,1,new QTableWidgetItem(dish_name[row]));
        }
}
//点击add按钮
void add_dish::on_pushButton_clicked()
{
    //食物类别
     string name1=ui->typename_2->text().toStdString();
    //食物数量
     int num_food=ui->comboBox->currentText().toInt();
     //食物列表
     QStringList food_name;
     qDebug()<<dish_name.size();
     for(int i=0;i<dish_name.size()-1;i++){
        if(ui->tableWidget->item(i,0)->checkState()){
            qDebug()<< QString("当前选择了第")<<i<<QString("行");
            food_name.append(ui->tableWidget->item(i,1)->text());
            QTableWidgetItem *check = new QTableWidgetItem();
            check->setCheckState(Qt::Unchecked);
            ui->tableWidget->setItem(i,0,check);
        }
     }
     qDebug()<<"获取全部内容";
     qDebug()<<QString::fromStdString(name1);
     qDebug()<<num_food;
     qDebug()<<food_name;





}

//点击套餐组合完成
void add_dish::on_pushButton_2_clicked()
{
    QMessageBox::information(this,tr("success"),tr("套餐已添加完成"),QMessageBox::Yes);
    this->close();
}

